﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;


namespace LoginForm
{
    public partial class NotePage : MyFormPage
    {        
        public NotePage()
        {
            InitializeComponent();
            this.pnl = pnlNotePage;
        }

        private void newNote_Click(object sender, EventArgs e)
        {
            txrNote.Text = "";
        }

        private void openNote_Click(object sender, EventArgs e)
        {
            Stream stream;
            OpenFileDialog openDialog = new OpenFileDialog();
            if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                stream = openDialog.OpenFile();
                if (stream != null) {
                    string filename = openDialog.FileName;
                    try
                    {
                        string content = File.ReadAllText(filename);
                        txrNote.Text = content;
                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }

        private void saveNote_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "Text File Document (*.txt)|*.txt";
            if(saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK){
                FileStream s = File.Open(saveDialog.FileName, FileMode.CreateNew);
                using(StreamWriter sw = new StreamWriter(s)){
                    sw.Write(txrNote.Text);
                }
            }
        }
        
    }
}
